package itdep.domain.division;

import itdep.domain.CodedEntity;
import org.hibernate.annotations.DiscriminatorFormula;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Type;

import javax.persistence.*;
import java.util.Arrays;

/**
 * @author Ivan Khalopik
 * @version $Revision: 13 $ $Date: 2010-06-16 13:04:42 +0000 (Wed, 16 Jun 2010) $
 */
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorFormula(value = "DEPARTMENT_TYPE")
@DiscriminatorValue(value = "0")
@Table(name = "DEPARTMENT")
public class Department extends CodedEntity {

	@Type(type = "ga.hibernate.OrderedEnumUserType", parameters = {@Parameter(name = "enumClass", value = "itdep.domain.division.DepartmentType")})
	@Column(name = "DEPARTMENT_TYPE", nullable = false)
	private DepartmentType type;

	@ManyToOne
	@JoinColumn(name = "ID_HEAD_DEPARTMENT", nullable = true)
	private Department headDepartment;

	@ManyToOne
	@JoinColumn(name = "ID_CHIEF", nullable = true)
	private Employee chief;

	public Department() {
		this(DepartmentType.OTHER);
	}

	protected Department(DepartmentType type) {
		super("department", Arrays.asList("description", "abbrev", "alternative"));
		this.type = type;
	}

	public Department getHeadDepartment() {
		return headDepartment;
	}

	public void setHeadDepartment(Department headDepartment) {
		this.headDepartment = headDepartment;
	}

	public DepartmentType getType() {
		return type;
	}

	public Employee getChief() {
		return chief;
	}

	public void setChief(Employee chief) {
		this.chief = chief;
	}
}